package com.javacommunity.model.entity;

// Generated Nov 25, 2014 11:55:44 PM by Hibernate Tools 3.4.0.CR1

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "category", catalog = "db_javadanang", uniqueConstraints = @UniqueConstraint(columnNames = "categoryName"))
public class Category implements java.io.Serializable {

    private Integer categoryId;
    private CategoryType categoryType;
    private String categoryName;
    private boolean active;
    private List<Post> posts = new ArrayList<Post>();

    public Category() {
    }

    public Category(CategoryType categoryType, String categoryName,
            boolean active) {
        this.categoryType = categoryType;
        this.categoryName = categoryName;
        this.active = active;
    }

    public Category(CategoryType categoryType, String categoryName,
            boolean active, List<Post> posts) {
        this.categoryType = categoryType;
        this.categoryName = categoryName;
        this.active = active;
        this.posts = posts;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "categoryId", unique = true, nullable = false)
    public Integer getCategoryId() {
        return this.categoryId;
    }

    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @Fetch (FetchMode.SELECT)
    @JoinColumn(name = "categoryTypeId", nullable = false)
    public CategoryType getCategoryType() {
        return this.categoryType;
    }

    public void setCategoryType(CategoryType categoryType) {
        this.categoryType = categoryType;
    }

    @Column(name = "categoryName", unique = true, nullable = false, length = 45)
    public String getCategoryName() {
        return this.categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    @Column(name = "active", nullable = false)
    public boolean isActive() {
        return this.active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "category")
    @Fetch (FetchMode.SELECT)
    public List<Post> getPosts() {
        return this.posts;
    }

    public void setPosts(List<Post> posts) {
        this.posts = posts;
    }

}
